#!/bin/bash
version=1.7.2

arm_arch=$(cat /proc/cpuinfo | grep "CPU architecture: " | head -n1 |  awk -F": "  '{print $2}' | cut -c 1)
if [[ -n "$arm_arch" ]] && [[ "$arm_arch" == "6" ]]; then
  wget -O /tmp/tldr https://github.com/tealdeer-rs/tealdeer/releases/download/v${version}/tealdeer-linux-arm-musleabihf || error "Failed to download tldr!"
else
  wget -O /tmp/tldr https://github.com/tealdeer-rs/tealdeer/releases/download/v${version}/tealdeer-linux-armv7-musleabihf || error "Failed to download tldr!"
fi
sudo mv /tmp/tldr /usr/bin/ || error "Failed to move binary to /usr/bin/"
sudo chmod +x /usr/bin/tldr
tldr --update
